From 0db5720a825154d189c28ae1a04b31f28234a703 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 19 Jan 2005 09:33:19 +0000 Subject: [PATCH] * Add $wgNoFollowLinks option to add rel="nofollow" on external links (on by default) --- includes/DefaultSettings.php | 8 +++++ includes/Linker.php | 4 +++ maintenance/parserTests.php | 1 + maintenance/parserTests.txt | 70 ++++++++++++++++++------------------ 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f3b5b883b4..1a18dc21c4 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1017,6 +1017,14 @@ $wgDisableInternalSearch = false; */ $wgSearchForwardUrl = null; +/** + * If true, external URL links in wiki text will be given the + * rel="nofollow" attribute as a hint to search engines that + * they should not be followed for ranking purposes as they + * are user-supplied and thus subject to spamming. + */ +$wgNoFollowLinks = true; + } else { die(); } diff --git a/includes/Linker.php b/includes/Linker.php index 59766bc269..3edca4b892 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -649,6 +649,10 @@ class Linker { function makeExternalLink( $url, $text, $escape = true, $linktype = '' ) { $style = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype ); + global $wgNoFollowLinks; + if( $wgNoFollowLinks ) { + $style .= ' rel="nofollow"'; + } $url = htmlspecialchars( $url ); if( $escape ) { $text = htmlspecialchars( $text ); diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 575e19255a..d7b94687d0 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -299,6 +299,7 @@ class ParserTest { 'wgMaxTocLevel' => 999, 'wgCapitalLinks' => true, 'wgDefaultUserOptions' => array(), + 'wgNoFollowLinks' => true, ); $this->savedGlobals = array(); foreach( $settings as $var => $val ) { diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt index 5cb7e1fabf..79a6afddf5 100644 --- a/maintenance/parserTests.txt +++ b/maintenance/parserTests.txt @@ -276,7 +276,7 @@ Definition list with URL link !! input ; http://example.com/ : definition !! result -
http://example.com/ 
definition +
http://example.com/ 
definition
!! end @@ -286,7 +286,7 @@ Definition list with bracketed URL link !! input ;[http://www.google.com/ Google]:Number one search engine !! result -
Google
Number one search engine +
Google
Number one search engine
!! end @@ -307,7 +307,7 @@ Definition list with wikilink containing colon !! input ; news:alt.wikipedia.rox: This isn't even a real newsgroup! !! result -
news:alt.wikipedia.rox
This isn't even a real newsgroup! +
news:alt.wikipedia.rox
This isn't even a real newsgroup!
!! end @@ -317,7 +317,7 @@ Malformed definition list with colon !! input ; news:alt.wikipedia.rox -- don't crash or enter an infinite loop !! result -
news:alt.wikipedia.rox -- don't crash or enter an infinite loop +
news:alt.wikipedia.rox -- don't crash or enter an infinite loop
!! end @@ -327,7 +327,7 @@ Definition lists: colon in external link text !! input ; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up !! result -
Wikipedia : The Next Generation
OK, I made that up +
Wikipedia : The Next Generation
OK, I made that up
!! end @@ -341,7 +341,7 @@ External links: non-bracketed !! input Non-bracketed: http://example.com !! result -

Non-bracketed: http://example.com +

Non-bracketed: http://example.com

!! end @@ -350,7 +350,7 @@ External links: numbered !! input Numbered: [http://example.com] !! result -

Numbered: [1] +

Numbered: [1]

!!end @@ -359,7 +359,7 @@ External links: specified text !! input Specified text: [http://example.com link] !! result -

Specified text: link +

Specified text: link

!!end @@ -368,7 +368,7 @@ External links: trail !! input Trail (not sure if this is meant to work): [http://example.com link]s !! result -

Trail (not sure if this is meant to work): links +

Trail (not sure if this is meant to work): links

!! end @@ -377,7 +377,7 @@ External links: dollar sign in URL !! input http://example.com/1$2345 !! result -

http://example.com/1$2345 +

http://example.com/1$2345

!! end @@ -386,7 +386,7 @@ External links: dollar sign in URL (named) !! input [http://example.com/1$2345] !! result -

[1] +

[1]

!!end @@ -413,7 +413,7 @@ Link to non-http image, no img tag !! input Link to non-http image, no img tag: ftp://example.com/test.jpg !! result -

Link to non-http image, no img tag: ftp://example.com/test.jpg +

Link to non-http image, no img tag: ftp://example.com/test.jpg

!! end @@ -422,7 +422,7 @@ External links: terminating separator !! input Terminating separator: http://example.com/thing, !! result -

Terminating separator: http://example.com/thing, +

Terminating separator: http://example.com/thing,

!! end @@ -431,7 +431,7 @@ External links: intervening separator !! input Intervening separator: http://example.com/1,2,3 !! result -

Intervening separator: http://example.com/1,2,3 +

Intervening separator: http://example.com/1,2,3

!! end @@ -440,7 +440,7 @@ External links: old bug with URL in query !! input Old bug with URL in query: [http://example.com/thing?url=http://example.com link] !! result -

Old bug with URL in query: link +

Old bug with URL in query: link

!! end @@ -449,7 +449,7 @@ External links: old URL-in-URL bug, mixed protocols !! input And again with mixed protocols: [ftp://example.com?url=http://example.com link] !! result -

And again with mixed protocols: link +

And again with mixed protocols: link

!!end @@ -458,7 +458,7 @@ External links: URL in text !! input URL in text: [http://example.com http://example.com] !! result -

URL in text: http://example.com +

URL in text: http://example.com

!! end @@ -467,7 +467,7 @@ External links: Clickable images !! input ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png] !! result -

ja-style clickable images: Ncwikicol.png +

ja-style clickable images: Ncwikicol.png

!!end @@ -476,7 +476,7 @@ External links: raw ampersand !! input Old & use: http://x&y !! result -

Old & use: http://x&y +

Old & use: http://x&y

!! end @@ -485,7 +485,7 @@ External links: www.jpeg.org (bug 554) !! input http://www.jpeg.org !!result -

http://www.jpeg.org +

http://www.jpeg.org

!! end @@ -494,7 +494,7 @@ External links: URL within URL (original bug 2) !! input [http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp] !! result -

[1] +

[1]

!! end @@ -503,7 +503,7 @@ BUG 361: URL inside bracketed URL !! input [http://www.example.com/foo http://www.example.com/bar] !! result -

http://www.example.com/bar +

http://www.example.com/bar

!! end @@ -512,7 +512,7 @@ BUG 289: ">"-token in URL-tail !! input http://www.example.com/ !! result -

http://www.example.com/<hello> +

http://www.example.com/<hello>

!!end @@ -521,7 +521,7 @@ BUG 289: literal ">"-token in URL-tail !! input http://www.example.com/html !! result -

http://www.example.com/html +

http://www.example.com/html

!!end @@ -530,7 +530,7 @@ BUG 289: ">"-token in bracketed URL !! input [http://www.example.com/ stuff] !! result -

<hello> stuff +

<hello> stuff

!!end @@ -539,7 +539,7 @@ BUG 289: literal ">"-token in bracketed URL !! input [http://www.example.com/html stuff] !! result -

html stuff +

html stuff

!!end @@ -548,7 +548,7 @@ BUG 289: literal double quote at end of URL !! input http://www.example.com/"hello" !! result -

http://www.example.com/"hello" +

http://www.example.com/"hello"

!!end @@ -557,7 +557,7 @@ BUG 289: literal double quote in bracketed URL !! input [http://www.example.com/"hello" stuff] !! result -

"hello" stuff +

"hello" stuff

!!end @@ -566,7 +566,7 @@ External links: invalid character !! input [http://www.example.com test] !! result -

[http://www.example.com test] +

[http://www.example.com test]

!! end @@ -887,7 +887,7 @@ Plain link to URL !! input [[http://www.example.org]] !! result -

[[1]] +

[[1]]

!! end @@ -907,7 +907,7 @@ Piped link to URL !! input Piped link to URL: [[http://www.example.org|an example URL]] !! result -

Piped link to URL: [example URL] +

Piped link to URL: [example URL]

!! end @@ -1488,7 +1488,7 @@ Thumbnail image caption with a free URL !! input [[Image:foobar.jpg|thumb|http://example.com]] !! result - + !! end @@ -1774,7 +1774,7 @@ Bug 1219 URL next to image (good) !! input http://example.com [[Image:foobar.jpg]] !! result -

http://example.com Image:foobar.jpg +

http://example.com Image:foobar.jpg

!!end @@ -1783,7 +1783,7 @@ Bug 1219 URL next to image (broken) !! input http://example.com[[Image:foobar.jpg]] !! result -

http://example.comImage:foobar.jpg +

http://example.comImage:foobar.jpg

!!end @@ -1792,7 +1792,7 @@ Bug 1186 news: in the middle of text !! input http://en.wikinews.org/wiki/Wikinews:Workplace !! result -

http://en.wikinews.org/wiki/Wikinews:Workplace +

http://en.wikinews.org/wiki/Wikinews:Workplace

!!end -- 2.20.1